<?php

namespace App\Http\Validate\Activity;

use App\Http\Validate\AbstractBaseValidate;
use App\Models\Activity\ActivityActionModel;
use App\Models\Activity\ActivityModel;
use App\Models\BaseModel;
use App\Models\Kms\User\KmsUser;
use App\Models\Shop\ShopModel;
use Illuminate\Support\Carbon;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class ActivityValidate extends AbstractBaseValidate
{
    function getRules(): array
    {
        // TODO: Implement getRules() method.
        return [];
    }

    function getAttributes(): array
    {
        // TODO: Implement getAttributes() method.
        return [
            "superScreenStartTime" => "霸屏开始时间",
            "superScreenEndTime"   => "霸屏结束时间",
            "startTime"            => "活动开始时间",
            "endTime"              => "活动结束时间",
            "systemNotifyCenterId" => "消息中心id",
            "actions"              => "动作选项"
        ];
    }

    function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.
    }

    function getMessages(): array
    {
        // TODO: Implement getMessages() method.
        return [];
    }

    /**
     * 活动列表校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function indexValidate(array $params)
    {
        return self::getInstance()->validate(
            [
                "pageSize",
                "pageNum",
                "name",
                "activityType",
                "startTime",
                "endTime",
                "joinRestrict",
                "superScreenSwitch",
                "superScreenStartTime",
                "superScreenEndTime",
                "minPrice",
                "maxPrice",
                "goodsId",
                "remark",
                "status",
                "actionName"
            ],
            $params,
            [
                "pageSize"             => "required|int|min:1|max:100",
                "pageNum"              => "required|int|min:1",
                "name"                 => "sometimes|string|min:1",
                "activityType"         => [
                    "sometimes",
                    "int",
                    "in:" . implode(",", array_keys(ActivityModel::ACTIVITY_TYPE_TEXT))
                ],
                "startTime"            => "required_with:endTime|date_format:Y-m-d",
                "endTime"              => "required_with:startTime|date_format:Y-m-d",
                "joinRestrict"         => "sometimes|string",
//                "noFirstOrder"         => self::intInValidateBuild(false, ActivityModel::SWITCH_TEXT),
//                "noLogisticsFile"      => self::intInValidateBuild(false, ActivityModel::SWITCH_TEXT),
//                "pauseShop"            => self::intInValidateBuild(false, ActivityModel::SWITCH_TEXT),
//                "closeShop"            => self::intInValidateBuild(false, ActivityModel::SWITCH_TEXT),
//                "prepareShop"          => self::intInValidateBuild(false, ActivityModel::SWITCH_TEXT),
//                "siteSelectionShop"    => self::intInValidateBuild(false, ActivityModel::SWITCH_TEXT),
                "superScreenSwitch"    => [
                    "sometimes",
                    "int",
                    "in:" . implode(",", array_keys(ActivityModel::SWITCH_TEXT))
                ],
                "superScreenStartTime" => "required_with:superScreenEndTime|date_format:Y-m-d",
                "superScreenEndTime"   => "required_with:superScreenStartTime|date_format:Y-m-d",
                "minPrice"             => "sometimes|numeric",
                "maxPrice"             => "sometimes|numeric",
                "goodsId"              => "sometimes|int",
                "remark"               => "sometimes|string",
                "status"               => "sometimes|in:" . self::enumTransToRules(ActivityModel::STATUS_TEXT),
                "actionName"           => "sometimes|string",
            ],
            true,
            function ($params) {
                $params["joinRestrict"] = explode(",", $params["joinRestrict"] ?? "");
                return $params;
            }
        );
    }

    /**
     * 新增校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function storeValidate(array $params)
    {
        return self::getInstance()->validate(
            [
                "name",
                "activityType",
                "shopType",
                "joinShopIds",
                "expireType",
                "startTime",
                "endTime",
                "joinRestrict",
                "blackShopIds",
                "whiteShopIds",
                "popUpTitle",
                "popUpContent",
                "superScreenSwitch",
                "superScreenStartTime",
                "superScreenEndTime",
                "superScreenBeforeContent",
                "superScreenAfterContent",
                "detail",
                "remark",
                "feedbackImgSwitch",
                "feedbackExampleImages",
                "remindSwitch",
                "superScreenFrequency",
                "remindStartTime",
                "remindEndTime",
                "systemNotifyCenterId",
                "remindDailyTime",
                "remindCycle",
                "actions"
            ],
            $params,
            [
                "name"                                  => self::stringValidateBuild(true, 120, 1),
                "activityType"                          => self::intInValidateBuild(true,
                    ActivityModel::ACTIVITY_TYPE_TEXT),
                "shopType"                              => self::intInValidateBuild(true,
                    ActivityModel::SHOP_TYPE_TEXT),
                "joinShopIds"                           => [
                    "exclude_unless:shopType," . ActivityModel::SHOP_TYPE_PART,
                    "required",
                    "array"
                ],
                "joinShopIds.*"                         => [
                    "int",
                    Rule::exists((new ShopModel())->getTable(), "id")
                ],
                "expireType"                            => self::intInValidateBuild(true,
                    ActivityModel::EXPIRE_TYPE_TEXT),
                "startTime"                             => [
                    "exclude_unless:expireType," . ActivityModel::EXPIRE_TYPE_1,
                    "required",
                    "date_format:Y-m-d"
                ],
                "endTime"                               => [
                    "exclude_unless:expireType," . ActivityModel::EXPIRE_TYPE_1,
                    "required",
                    "date_format:Y-m-d",
                    "after_or_equal:startTime",
                    "after_or_equal:" . Carbon::now()->startOfDay()
                ],
                "joinRestrict"                          => "array",
                "joinRestrict.*"                        => [
                    "string",
                    "in:" . self::enumTransToRules(ActivityModel::JOIN_RESTRICT_TEXT)
                ],
                "blackShopIds"                          => "array",
                "blackShopIds.*"                        => [
                    "int",
                    Rule::exists((new ShopModel())->getTable(), "id")
                ],
                "whiteShopIds"                          => "array",
                "whiteShopIds.*"                        => [
                    "int",
                    Rule::exists((new ShopModel())->getTable(), "id")
                ],
                "popUpTitle"                            => "sometimes|string|max:120",
                "popUpContent"                          => "required|string",
                "superScreenSwitch"                     => self::intInValidateBuild(true, ActivityModel::SWITCH_TEXT),
                "superScreenStartTime"                  => [
                    "exclude_unless:superScreenSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "date_format:Y-m-d H:i:s",
                    Rule::when(
                        $params["expireType"] == ActivityModel::EXPIRE_TYPE_1,
                        [
                            vsprintf("before_or_equal:%s 23:59:59", [$params["endTime"] ?? ""]),
                            "after:startTime"
                        ],
                        ""
                    )
                ],
                "superScreenEndTime"                    => [
                    "exclude_unless:superScreenSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "date_format:Y-m-d H:i:s",
                    "after:superScreenStartTime",
                    Rule::when(
                        $params["expireType"] == ActivityModel::EXPIRE_TYPE_1,
                        [
                            vsprintf("before_or_equal:%s 23:59:59", [$params["endTime"] ?? ""]),
                            "after:startTime"
                        ],
                        ""
                    )
                ],
                "superScreenFrequency"                  => self::intInValidateBuild(
                    true, ActivityModel::SUPER_SCREEN_FREQUENCY_TEXT
                ),
                "superScreenBeforeContent"              => [
                    "exclude_unless:superScreenSwitch," . ActivityModel::SWITCH_ON,
                    "sometimes",
                    "string",
                    "max:200"
                ],
                "superScreenAfterContent"               => [
                    "exclude_unless:superScreenSwitch," . ActivityModel::SWITCH_ON,
                    "sometimes",
                    "string",
                    "max:200"
                ],
                "detail"                                => "required|string",
                "remark"                                => "sometimes|string|max:255",
                "feedbackImgSwitch"                     => self::intInValidateBuild(true, ActivityModel::SWITCH_TEXT),
                "feedbackExampleImages"                 => [
                    "exclude_unless:feedbackImgSwitch," . ActivityModel::SWITCH_ON,
                    "sometimes",
                    "array"
                ],
                "feedbackExampleImages.*"               => [
                    "exclude_unless:feedbackImgSwitch," . ActivityModel::SWITCH_ON,
                    "url"
                ],
                "remindSwitch"                          => self::intInValidateBuild(true, ActivityModel::SWITCH_TEXT),
                "remindStartTime"                       => [
                    "exclude_unless:remindSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "date_format:Y-m-d",
                ],
                "remindEndTime"                         => [
                    "exclude_unless:remindSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "date_format:Y-m-d",
                    "after_or_equal:remindStartTime",
                    "after_or_equal:" . Carbon::now()->startOfDay()
                ],
                "systemNotifyCenterId"                  => [
                    "exclude_unless:remindSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "int",
                    "gt:0"
                ],
                "remindDailyTime"                       => [
                    "exclude_unless:remindSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "date_format:H:i:s"
                ],
                "remindCycle"                           => [
                    "exclude_unless:remindSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "array"
                ],
                "remindCycle.*"                         => [
                    "int",
                    "in:0,1,2,3,4,5,6"
                ],
                "actions"                               => "required|array",
                "actions.*.name"                        => self::stringValidateBuild(true, 120, 1),
                "actions.*.hiddenSwitch"                => self::intInValidateBuild(true, ActivityModel::SWITCH_TEXT),
                "actions.*.actionType"                  => self::intInValidateBuild(
                    true, ActivityActionModel::ACTION_TYPE_TEXT
                ),
                "actions.*.remark"                      => "string",
                "actions.*.sort"                        => "required|int|gte:0",
                "actions.*.price"                       => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "int",
                    "gt:0"
                ],
                "actions.*.originalPrice"               => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "int",
                    "gt:0"
                ],
                "actions.*.goodsId"                     => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "int",
                    "gt:0"
                ],
                "actions.*.goodsNum"                    => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "int",
                    "gt:0"
                ],
                "actions.*.goodsInfo"                   => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "array"
                ],
                "actions.*.goodsInfo.code"              => [
                    "required",
                    "string"
                ],
                "actions.*.goodsInfo.spec"              => [
                    "string"
                ],
                "actions.*.goodsInfo.id"                => [
                    "required",
                    "int"
                ],
                "actions.*.goodsInfo.name"              => [
                    "required",
                    "string"
                ],
//                "actions.*.shippingAddressSwitch"       => [
//                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
//                    "required",
//                    "in:" . self::enumTransToRules(ActivityModel::SWITCH_TEXT)
//                ],
                "actions.*.shippingAddressType"         => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "in:" . self::enumTransToRules(ActivityActionModel::SHIPPING_ADDRESS_TEXT)
                ],
                "actions.*.formTemplateId"              => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "required",
                    "int",
                    "gt:0"
                ],
                "actions.*.examineSwitch"               => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "required",
                    "in:" . self::enumTransToRules(ActivityModel::SWITCH_TEXT)
                ],
                "actions.*.examineUser"                 => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "exclude_unless:actions.*.examineSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "array"
                ],
                "actions.*.examineUser.*"               => [
                    "int",
                    "gt:0",
                    Rule::exists((new KmsUser())->getTable(), "rmsUserId")
                ],
//                "actions.*.examineUser.*.username"      => [
//                    "required",
//                    "string"
//                ],
                "actions.*.groupNotificationBotName"    => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "string",
                    "max:120"
                ],
                "actions.*.groupNotificationBotWebhook" => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "string",
                    "url"
                ],
                "actions.*.groupNotificationBotSecret"  => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "string",
                    "max:120"
                ],
            ],
            true,
            function ($params) {
                if ($params["remindSwitch"] == ActivityModel::SWITCH_OFF) {
                    unset($params["systemNotifyCenterId"]);
                }
                return $params;
            }
        );
    }

    /**
     * 新增校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function updateValidate(array $params)
    {
        return self::getInstance()->validate(
            [
                "id",
                "name",
                "activityType",
                "shopType",
                "joinShopIds",
                "expireType",
                "startTime",
                "endTime",
                "joinRestrict",
                "blackShopIds",
                "whiteShopIds",
                "popUpTitle",
                "popUpContent",
                "superScreenSwitch",
                "superScreenStartTime",
                "superScreenEndTime",
                "superScreenBeforeContent",
                "superScreenAfterContent",
                "detail",
                "remark",
                "feedbackImgSwitch",
                "feedbackExampleImages",
                "remindSwitch",
                "superScreenFrequency",
                "remindStartTime",
                "remindEndTime",
                "systemNotifyCenterId",
                "remindDailyTime",
                "remindCycle",
                "actions"
            ],
            $params,
            [
                "id"                                    => [
                    "required",
                    "int",
                    Rule::exists((new ActivityModel())->getTable(), "id")->where("isDeleted", BaseModel::DELETE_NO)
                ],
                "name"                                  => self::stringValidateBuild(true, 120, 1),
                "activityType"                          => self::intInValidateBuild(true,
                    ActivityModel::ACTIVITY_TYPE_TEXT),
                "shopType"                              => self::intInValidateBuild(true,
                    ActivityModel::SHOP_TYPE_TEXT),
                "joinShopIds"                           => [
                    "exclude_unless:shopType," . ActivityModel::SHOP_TYPE_PART,
                    "required",
                    "array"
                ],
                "joinShopIds.*"                         => [
                    "int",
                    Rule::exists((new ShopModel())->getTable(), "id")
                ],
                "expireType"                            => self::intInValidateBuild(true,
                    ActivityModel::EXPIRE_TYPE_TEXT),
                "startTime"                             => [
                    "exclude_unless:expireType," . ActivityModel::EXPIRE_TYPE_1,
                    "required",
                    "date_format:Y-m-d"
                ],
                "endTime"                               => [
                    "exclude_unless:expireType," . ActivityModel::EXPIRE_TYPE_1,
                    "required",
                    "date_format:Y-m-d",
                    "after_or_equal:startTime",
                    "after_or_equal:" . Carbon::now()->startOfDay()
                ],
                "joinRestrict"                          => "array",
                "joinRestrict.*"                        => [
                    "string",
                    "in:" . self::enumTransToRules(ActivityModel::JOIN_RESTRICT_TEXT)
                ],
                "blackShopIds"                          => "array",
                "blackShopIds.*"                        => [
                    "int",
                    Rule::exists((new ShopModel())->getTable(), "id")
                ],
                "whiteShopIds"                          => "array",
                "whiteShopIds.*"                        => [
                    "int",
                    Rule::exists((new ShopModel())->getTable(), "id")
                ],
                "popUpTitle"                            => "sometimes|string|max:120",
                "popUpContent"                          => "required|string",
                "superScreenSwitch"                     => self::intInValidateBuild(true, ActivityModel::SWITCH_TEXT),
                "superScreenStartTime"                  => [
                    "exclude_unless:superScreenSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "date_format:Y-m-d H:i:s",
                    Rule::when(
                        $params["expireType"] == ActivityModel::EXPIRE_TYPE_1,
                        [
                            vsprintf("before_or_equal:%s 23:59:59", [$params["endTime"] ?? ""]),
                            "after:startTime"
                        ],
                        ""
                    )
                ],
                "superScreenEndTime"                    => [
                    "exclude_unless:superScreenSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "date_format:Y-m-d H:i:s",
                    "after:superScreenStartTime",
                    Rule::when(
                        $params["expireType"] == ActivityModel::EXPIRE_TYPE_1,
                        [
                            vsprintf("before_or_equal:%s 23:59:59", [$params["endTime"] ?? ""]),
                            "after:startTime"
                        ],
                        ""
                    )
                ],
                "superScreenFrequency"                  => self::intInValidateBuild(
                    true, ActivityModel::SUPER_SCREEN_FREQUENCY_TEXT
                ),
                "superScreenBeforeContent"              => [
                    "exclude_unless:superScreenSwitch," . ActivityModel::SWITCH_ON,
                    "sometimes",
                    "string",
                    "max:200"
                ],
                "superScreenAfterContent"               => [
                    "exclude_unless:superScreenSwitch," . ActivityModel::SWITCH_ON,
                    "sometimes",
                    "string",
                    "max:200"
                ],
                "detail"                                => "required|string",
                "remark"                                => "sometimes|string|max:255",
                "feedbackImgSwitch"                     => self::intInValidateBuild(true, ActivityModel::SWITCH_TEXT),
                "feedbackExampleImages"                 => [
                    "exclude_unless:feedbackImgSwitch," . ActivityModel::SWITCH_ON,
                    "sometimes",
                    "array"
                ],
                "feedbackExampleImages.*"               => [
                    "exclude_unless:feedbackImgSwitch," . ActivityModel::SWITCH_ON,
                    "url"
                ],
                "remindSwitch"                          => self::intInValidateBuild(true, ActivityModel::SWITCH_TEXT),
                "remindStartTime"                       => [
                    "exclude_unless:remindSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "date_format:Y-m-d",
                ],
                "remindEndTime"                         => [
                    "exclude_unless:remindSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "date_format:Y-m-d",
                    "after_or_equal:remindStartTime",
                    "after_or_equal:" . Carbon::now()->startOfDay()
                ],
                "systemNotifyCenterId"                  => [
                    "exclude_unless:remindSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "int",
                    "gt:0"
                ],
                "remindDailyTime"                       => [
                    "exclude_unless:remindSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "date_format:H:i:s"
                ],
                "remindCycle"                           => [
                    "exclude_unless:remindSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "array"
                ],
                "remindCycle.*"                         => [
                    "int",
                    "in:0,1,2,3,4,5,6"
                ],
                "actions"                               => "required|array",
                "actions.*.id"                          => [
                    "required",
                    "int",
                    "gte:0"
                ],
                "actions.*.name"                        => self::stringValidateBuild(true, 120, 1),
                "actions.*.hiddenSwitch"                => self::intInValidateBuild(true, ActivityModel::SWITCH_TEXT),
                "actions.*.actionType"                  => self::intInValidateBuild(
                    true, ActivityActionModel::ACTION_TYPE_TEXT
                ),
                "actions.*.remark"                      => "string",
                "actions.*.sort"                        => "required|int|gte:0",
                "actions.*.price"                       => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "int",
                    "gt:0"
                ],
                "actions.*.originalPrice"               => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "int",
                    "gt:0"
                ],
                "actions.*.goodsId"                     => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "int",
                    "gt:0"
                ],
                "actions.*.goodsNum"                    => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "int",
                    "gt:0"
                ],
                "actions.*.goodsInfo"                   => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "array"
                ],
                "actions.*.goodsInfo.code"              => [
                    "required",
                    "string"
                ],
                "actions.*.goodsInfo.spec"              => [
                    "string"
                ],
                "actions.*.goodsInfo.id"                => [
                    "required",
                    "int"
                ],
                "actions.*.goodsInfo.name"              => [
                    "required",
                    "string"
                ],
//                "actions.*.shippingAddressSwitch"       => [
//                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
//                    "required",
//                    "in:" . self::enumTransToRules(ActivityModel::SWITCH_TEXT)
//                ],
                "actions.*.shippingAddressType"         => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_1,
                    "required",
                    "in:" . self::enumTransToRules(ActivityActionModel::SHIPPING_ADDRESS_TEXT)
                ],
                "actions.*.formTemplateId"              => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "required",
                    "int",
                    "gt:0"
                ],
                "actions.*.examineSwitch"               => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "required",
                    "in:" . self::enumTransToRules(ActivityModel::SWITCH_TEXT)
                ],
                "actions.*.examineUser"                 => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "exclude_unless:actions.*.examineSwitch," . ActivityModel::SWITCH_ON,
                    "required",
                    "array"
                ],
                "actions.*.examineUser.*"               => [
                    "int",
                    "gt:0",
                    Rule::exists((new KmsUser())->getTable(), "rmsUserId")
                ],
//                "actions.*.examineUser.*.username"      => [
//                    "required",
//                    "string"
//                ],
                "actions.*.groupNotificationBotName"    => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "string",
                    "max:120"
                ],
                "actions.*.groupNotificationBotWebhook" => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "string",
                    "url"
                ],
                "actions.*.groupNotificationBotSecret"  => [
                    "exclude_unless:actions.*.actionType," . ActivityActionModel::ACTION_TYPE_2,
                    "string",
                    "max:120"
                ],
            ],
            true,
            function ($params) {
                if ($params["remindSwitch"] == ActivityModel::SWITCH_OFF) {
                    unset($params["systemNotifyCenterId"]);
                }
                return $params;
            }
        );
    }

    /**
     * 展示校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function showValidate(array $params)
    {
        return self::getInstance()->validate(
            [
                "id"
            ],
            $params,
            [
                "id" => [
                    "required",
                    "int",
                    Rule::exists((new ActivityModel())->getTable(), "id")->where("isDeleted", BaseModel::DELETE_NO)
                ]
            ]
        );
    }

    /**
     * 详情校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function statusValidate(array $params)
    {
        return self::getInstance()->validate(
            ["id", "status"],
            $params,
            [
                "id"     => [
                    "required",
                    "int",
                    Rule::exists((new ActivityModel())->getTable(), "id")
                        ->where("isDeleted", 0)
                        ->whereIn("status", [
                            ActivityModel::STATUS_0,
                            ActivityModel::STATUS_1,
                            ActivityModel::STATUS_2,
                        ])
                ],
                "status" => [
                    "required",
                    "int",
                    vsprintf("in:%s,%s", [
                        ActivityModel::STATUS_1,
                        ActivityModel::STATUS_2,
                    ])
                ]
            ]
        );
    }

    /**
     * 结束校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function finishValidate(array $params)
    {
        return self::getInstance()->validate(
            ["id"],
            $params,
            [
                "id" => [
                    "required",
                    "int",
                    Rule::exists((new ActivityModel())->getTable(), "id")
                        ->where("isDeleted", 0)
                        ->whereNotIn("status", [ActivityModel::STATUS_3])
                ]
            ]
        );
    }

    /**
     * 活动参与数据统计校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function joinStatisticsValidate(array $params)
    {
        return self::getInstance()->validate(
            [
                "id",
                "pageSize",
                "pageNum",
                "name",
                "activityType",
                "actionName",
                "startTime",
                "endTime",
                "shopId",
                "export",
                "status"
            ],
            $params,
            [
                "pageSize"     => "required|int|min:1|max:100",
                "pageNum"      => "required|int|min:1",
                "id"           => "sometimes|int|gt:0",
                "name"         => "sometimes|string",
                "activityType" => "sometimes|in:" . self::enumTransToRules(ActivityModel::ACTIVITY_TYPE_TEXT),
                "actionName"   => "sometimes|string",
                "startTime"    => "required_with:endTime|date_format:Y-m-d",
                "endTime"      => "required_with:startTime|date_format:Y-m-d",
                "shopId"       => "sometimes|int|gt:0",
                "export"       => "required|int|in:0,1",
                "status"       => "sometimes|in:" . self::enumTransToRules(ActivityModel::STATUS_TEXT)
            ]
        );
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function joinStatisticsShopListValidate(array $params)
    {
        return self::getInstance()->validate(
            [
                "pageSize",
                "pageNum",
                "export",
                "shopId",
                "businessExportType",
                "activityId"
            ],
            $params,
            [
                "businessExportType" => self::intInValidateBuild(true, ActivityModel::BUSINESS_EXPORT_TYPE_TEXT),
                "activityId"         => [
                    "required",
                    "int",
                    Rule::exists((new ActivityModel())->getTable(), "id")
                ],
                "pageSize"           => "exclude_unless:export,0|required|int|min:1|max:100",
                "pageNum"            => "exclude_unless:export,0|required|int|min:1",
                "export"             => "required|int|in:0,1",
                "shopId"             => "sometimes|int|min:1"
            ]
        );
    }
}
